<template>
	<view class="container">
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index" @click="pageTo(item)">
				<view class="title u-flex u-col-center u-row-between">
					<view class="l">
						{{item.title}}
					</view>
					<view class="r" v-if="item.see == 0">

					</view>
				</view>
				<view class="info">
					{{item.content}}
				</view>
				<view class="more-time u-flex u-col-center u-row-between">
					<view class="time">
						{{item.createTime | formatISODate}}
					</view>
					<view class="more">
						查看
					</view>
				</view>
			</view>
			<view class="nolist" v-if="nolist">
				<image src="/static/kong3.png" mode="aspectFill"></image>
				<text>暂无消息</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		messageList,messageSeecount
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				list: [],
				params: {
					page: 1,
					limit: 10,
				},
				nolist: false,
			}
		},
		onLoad() {
			this.getlist()
		},
		onShow() {
			this.getSeeCount()
		},
		onReachBottom() {
			this.params.page++
			this.getlist()
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中...'
			})
			this.params.page = 1
			this.list = []
			this.getlist()
			setTimeout(() => {
				uni.hideLoading()
				uni.stopPullDownRefresh()
			}, 500)
		},
		methods: {
			getSeeCount() {
				messageSeecount({}).then(res => {
					if (res.code == 200) {
						let num = res.data
						if (num > 0) {
							uni.setTabBarBadge({
								index: 1,
								text: '新'
							})
						} else {
							uni.removeTabBarBadge({
								index: 1
							})
						}
					}
				})
			},
			getlist() {
				messageList(this.params).then(res => {
					if (res.code == 200) {
						this.list.push(...res.data.list)
						let total = Math.ceil(res.data.total / this.params.limit);
						this.nolist = total == 0
					}
				})
			},
			pageTo(item) {
				item.see = 1
				uni.navigateTo({
					url: `/pages/message/msginfo?id=${item.id}`
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 20rpx;

		.nolist {
			padding: 360rpx 30rpx 30rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			text-align: center;

			image {
				width: 360rpx;
				height: 236rpx;
			}

			text {
				font-size: 28rpx;
				color: #979797;
				margin-top: 20rpx;
			}
		}

		.list {
			.item {
				background-color: #fff;
				padding: 20rpx;
				border-radius: 10rpx;
				margin-bottom: 20rpx;

				.title {
					height: 40rpx;
					line-height: 40rpx;
					font-weight: bold;
					font-size: 30rpx;
					color: #11192D;
					text-align: left;

					.l {
						flex: 1;
						width: 1rpx;
						margin-right: 20rpx;
					}

					.r {
						width: 16rpx;
						height: 16rpx;
						background: #FF1717;
						border-radius: 8rpx;
					}

				}

				.info {
					padding: 20rpx 0;
					border-bottom: 2rpx solid #eee;
					font-size: 28rpx;
					color: #979797;
					text-align: left;
				}

				.more-time {
					line-height: 40rpx;
					height: 40rpx;
					font-size: 28rpx;
					color: #979797;
					margin-top: 20rpx;

					.more {
						text-align: right;
					}

					.titme {}
				}
			}
		}
	}
</style>